package com.example.bgmachine.bgmachine;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bgmachine.bgmachine.commons.CleanConfigRecord;
import com.example.bgmachine.bgmachine.commons.CleanDatabaseRecord;
import com.example.bgmachine.bgmachine.coms.LogUtils;
import com.example.bgmachine.bgmachine.databases.MyDatabaseInfor;
import com.example.bgmachine.bgmachine.datas.CleanDataRecord;
import com.example.bgmachine.bgmachine.datas.CleanRunRecord;
import com.example.bgmachine.bgmachine.datas.DataInfors;
import com.example.bgmachine.bgmachine.exts.DevicesInfors;
import com.example.bgmachine.bgmachine.homes.HomePages;
import com.example.bgmachine.bgmachine.logins.LoginViews;
import com.example.bgmachine.bgmachine.logs.DebugUtils;
import com.example.bgmachine.bgmachine.waitviews.ProducewaitCirclePgBar;
import com.example.bgmachine.bgmachine.waitviews.WeiboDialogUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;

public class MainActivity extends AppCompatActivity {
    private boolean mIsVirtual = false;

    private static final int SCREEN_STATUS = 0;
    private static final int SCREEN_ERROR = 1;
    private static final int SCREEN_MATERIAL = 2;
    private static final int SCREEN_CLEAN = 3;
    private static final int SCREEN_MAKE = 4;
    private static final int SCREEN_MENU = 5;
    private static final int SCREEN_LOGIN = 6;
    private static final int LOGIN_ERROR = 7;
    private static final int DEVICES_LIST = 8;
    private static final int DEVICES_ERROR = 9;
    private static final int DEVICES_CHECK = 10;
    private static final int DEVICES_CHECK_ERROR = 11;
    private static final int DEVICES_STATUS = 12;
    private static final int DEVICES_STATUS_ERROR = 13;


    private RelativeLayout mani_background_one = null;
    private RelativeLayout mani_background_two = null;
    private RelativeLayout mid_background_one = null;
    private RelativeLayout mid_background_two = null;


    private EditText devices_edittext = null;
    private Button devices_button = null;
    private String m_deviceNumbers = "";

    private Button devices_login_button = null;
    private Spinner devices_spin_pot = null;

    private LoginViews mLoginViews = null;
    private String m_userNames = "";
    private String m_userPwds = "";

    public String mdevicenums = "";
    public String mError = "";
    public boolean misversion = false;
    public int mSelectIndexs = 0;
    public String mCurrenpahts = "";

    private Urlinfor mUrlinfor = new Urlinfor();
    private Context mContext = null;
    private TextView mtxtVersionTip = null;
    private TextView mtxtErrorTip = null;
    private RelativeLayout producewait_circlepg_bar_background = null;
    private ProducewaitCirclePgBar producewait_circlepg_bar = null;
    private Button main_local_infor_network_btn = null;
    private Button main_local_infor_local_btn = null;
    private JSONArray mCuurentArry = new JSONArray();
    private UpdateManger mupdatemanager = null;
    private Dialog mWeiboDialog = null;
    public int mPageIndexs = 0;
    public int mPageLimit = 1;
    public int mPageAlls = 0;
    public Handler handler = new Handler() {

        @SuppressLint("HandlerLeak")
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Log.d("aaaaa", "ccccc: ");
            //   Toast.makeText(mContext, "myTopic myTopic="+myTopic , Toast.LENGTH_SHORT).show();
            switch (msg.what) {
                case SCREEN_STATUS:
                    if (mWeiboDialog != null) {
                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                    }
                    Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                    String responsa = (String) msg.obj;
                    Log.d("aaaaa", "c=1=" + responsa);

                    try {
                        JSONObject jsonObject = new JSONObject(responsa);
                        boolean status = jsonObject.optBoolean("status");
                        Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                        if (status) {
                            JSONObject rows = jsonObject.optJSONObject("rows");
                            String device_status = rows.optString("device_status");
                            String auto_check = rows.optString("auto_check");

                            String upgrade_version = rows.optString("upgrade_version");
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            if (upgrade_version.length() > 0) {
                                if (!upgrade_version.equals(Urlinfor.getmUrlinfor().mVersion)) {
                                    if (mWeiboDialog != null) {
                                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                                    }
                                    Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                                    updateApk(upgrade_version);
                                    Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                                    return;
                                }

                            }
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            if (rows.has("logo_name")) {
                                String logo_name = rows.optString("logo_name");
                                Log.d("aaaaa", "logo_name=1=" + logo_name);

                                Urlinfor.getmUrlinfor().setLogoImage(logo_name);
                            }
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            Urlinfor.getmUrlinfor().setAutoCheck(auto_check);
                            Urlinfor.getmUrlinfor().setDeviceStatus(device_status);
//                            if (Integer.parseInt(device_status) == 2) {
//                                mError = mContext.getResources().getString(R.string.main_local_device_error_two);
//                                String mysql_name = rows.optString("mysql_name");
//                                Urlinfor.getmUrlinfor().setMysqlName(mysql_name);
//                                String shopInformationId = rows.optString("shopInformationId");
//                                String no = rows.optString("no");
//
//                                Urlinfor.getmUrlinfor().setShopInformationId(shopInformationId);
//                                Urlinfor.getmUrlinfor().setShopInformationNo("");
//
//                              //  mtxtErrorTip.setText(mContext.getResources().getString(R.string.main_local_device_two) + mError);
//                               // mtxtErrorTip.setVisibility(TextView.VISIBLE);
//                               // return;
//                            } else {
                            String mysql_name = rows.optString("mysql_name");
                            Urlinfor.getmUrlinfor().setMysqlName(mysql_name);
                            String shopInformationId = rows.optString("shopInformationId");
                            String no = rows.optString("no");
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());

                            // 称重校验; 1: 开启; 2: 关闭
                            if (rows.has("weighing_verification_status")) {
                                String weighing_verification_status = rows.optString("weighing_verification_status");
                                DevicesInfors.getDevicesInfors().setWeighing_verification_status(Integer.parseInt(weighing_verification_status));
                                Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                                if (rows.has("verify_time")) {
                                    String verify_time = rows.optString("verify_time");
                                    Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                                    if (verify_time.length() > 0) {
                                        JSONArray jsonArraysa = new JSONArray(verify_time);
                                        for (int k = 0; k < jsonArraysa.length(); k++) {
                                            JSONObject objca = jsonArraysa.getJSONObject(k);

                                            String start_time = objca.optString("start_time");

                                            String end_time = objca.optString("end_time");
                                            DevicesInfors.getDevicesInfors().setmVerifyTime(start_time, end_time);
                                        }
                                        Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                                    }


                                }

                                Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            }
                            //支付方式1: 常规，2：支付；3：扫码
                            if (rows.has("device_type")) {
                                String device_type = rows.optString("device_type");
                                DevicesInfors.getDevicesInfors().setDevice_type(Integer.parseInt(device_type));
                            }

                            Urlinfor.getmUrlinfor().setShopInformationId(shopInformationId);
                            Urlinfor.getmUrlinfor().setShopInformationNo(no);
                            //  main_local_infor_local_btn.setVisibility(RelativeLayout.VISIBLE);
                            //   main_local_infor_network_btn.setVisibility(RelativeLayout.VISIBLE);
                            //    }
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            if (jsonObject.has("configs")) {
                                JSONObject configs = jsonObject.optJSONObject("configs");
                                if (configs.has("brandCodes")) {
                                    String brandCodes = configs.optString("brandCodes");
                                    Urlinfor.getmUrlinfor().setBrandCodes(brandCodes);
                                }
                            }
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            if (mSelectIndexs == 0) {
                                sendRequestInitDeviceMaterial();

                            } else {
                                sendRequestInitDeviceMkesales();


                            }
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                        } else {
                            if (mWeiboDialog != null) {
                                WeiboDialogUtils.closeDialog(mWeiboDialog);

                            }
                            Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                            int code = jsonObject.optInt("code");
                            if (code == 100) {
                                mError = mContext.getResources().getString(R.string.main_local_device_error_one);
                            }

                            mtxtErrorTip.setText(mContext.getResources().getString(R.string.main_local_device_two) + mError);
                            mtxtErrorTip.setVisibility(TextView.VISIBLE);
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                        Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                        if (mWeiboDialog != null) {
                            WeiboDialogUtils.closeDialog(mWeiboDialog);

                        }
                    }
                    break;
                case SCREEN_ERROR:
                    if (mWeiboDialog != null) {
                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                    }

                    mError = mContext.getResources().getString(R.string.main_local_device_error_one);
                    mtxtErrorTip.setText(mContext.getResources().getString(R.string.main_local_device_two) + mError);
                    mtxtErrorTip.setVisibility(TextView.VISIBLE);
                    break;

                case SCREEN_LOGIN:
//                    if(mLoginViews != null){
//                        mLoginViews.dismiss();
//                    }

                    String responsaf = (String) msg.obj;
                    Log.d("aaaaa", "responsaf=1=" + responsaf);

                    try {
                        JSONObject jsonObject = new JSONObject(responsaf);
                        boolean status = jsonObject.optBoolean("status");
                        if (!status) {
                            if (mWeiboDialog != null) {
                                WeiboDialogUtils.closeDialog(mWeiboDialog);

                            }
                            //   mError = mContext.getResources().getString(R.string.main_local_device_error_three);
                            // mtxtErrorTip.setText(mContext.getResources().getString(R.string.main_local_device_two) + mError);
                            //   mtxtErrorTip.setVisibility(TextView.VISIBLE);
                            Toast.makeText(mContext, mContext.getResources().getString(R.string.main_local_device_error_three), Toast.LENGTH_SHORT).show();
                        } else {
                            JSONObject rows = jsonObject.optJSONObject("rows");
                            int pers = jsonObject.optInt("pers");
                            // pers=1;
                            if (pers == 1) {
                                if (mLoginViews != null) {
                                    mLoginViews.dismiss();
                                }
                                String brand_id = rows.optString("brand_id");
                                if (brand_id.length() > 0) {
                                    DataInfors.getmUrlinfor().setBrandId(brand_id);
                                    sendRequestBrandDeviceList();
                                } else {
                                    if (mWeiboDialog != null) {
                                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                                    }
                                    if (devices_edittext != null) {
                                        devices_edittext.setText("");
                                    }
                                    if (mid_background_one != null) {
                                        mid_background_one.setVisibility(RelativeLayout.VISIBLE);
                                    }


                                }

                            } else {
                                if (mWeiboDialog != null) {
                                    WeiboDialogUtils.closeDialog(mWeiboDialog);

                                }
//                               mError = mContext.getResources().getString(R.string.main_local_device_error_four);
//                               mtxtErrorTip.setText(mContext.getResources().getString(R.string.main_local_device_two) + mError);
//                               mtxtErrorTip.setVisibility(TextView.VISIBLE);
                                Toast.makeText(mContext, mContext.getResources().getString(R.string.main_local_device_error_four), Toast.LENGTH_SHORT).show();
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();

                    }
                    break;
                case SCREEN_MATERIAL:
                    String responsc = (String) msg.obj;
                    Log.d("aaaaa", "responsc1==" + responsc);
                    ContentInfor.getmUrlinfor().setInforMaterial(responsc);
                    Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                    saveMaterialText(responsc);
                    sendRequestInitDeviceCleantime();
                    Log.d("aaa", "handleMessage: " + LogUtils.getMethodInfo());
                    break;
                case SCREEN_CLEAN:
                    String responsd = (String) msg.obj;
                    Log.d("aaaaa", "responsd==" + responsd);
                    ContentInfor.getmUrlinfor().setInforCleanTime(responsd);
                    saveCleanTimeText(responsd);
                    sendRequestInitDeviceMkesales();
                    break;
                case SCREEN_MAKE:
                    String response = (String) msg.obj;
                    Log.d("aaaaa", "response==" + response);
                    ContentInfor.getmUrlinfor().setInforMakes(response);
                    if (mSelectIndexs == 1) {
                        if (mWeiboDialog != null) {
                            WeiboDialogUtils.closeDialog(mWeiboDialog);
                        }

                        readCleanTimText();
                        readMaterialText();
                        readMenusText();

                        jumpPage();
                        return;
                    } else {
                        mPageIndexs = 1;
                        mPageAlls = 1;
                        mCuurentArry = new JSONArray();
                        sendRequestInitDeviceMenus();
                    }

                    break;
                case SCREEN_MENU:
                    String responsf = (String) msg.obj;
                    Log.d("aaaaa", "responsf==" + responsf);
                    //ContentInfor.getmUrlinfor().setInforMakes(response) ;
                    try {
                        JSONObject jsonObjecta = new JSONObject(responsf);
                        int totalPages = jsonObjecta.optInt("totalPages");
                        int page = Integer.parseInt(jsonObjecta.optString("page"));

                        JSONArray rows = jsonObjecta.optJSONArray("rows");
                        Log.d("aaa", "handle--rows " + rows.toString());
                        mCuurentArry = mergeJsonArrays(mCuurentArry, rows);

                        //mCuurentArry.put(rows);
                        Log.d("aaa", "handle--mCuurentArry==" + mCuurentArry.toString());
                        if (page >= totalPages) {
                            ContentInfor.getmUrlinfor().setInforMenus(mCuurentArry.toString());
                            saveMenusText(mCuurentArry.toString());
                            jumpPage();
                            return;
                        } else {
                            mPageIndexs++;
                            sendRequestInitDeviceMenus();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();

                    }
                    break;

                case DEVICES_LIST: {
                    if (mWeiboDialog != null) {
                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                    }

                    String responba = (String) msg.obj;
                    Log.d("aaaaa", "responba=1=" + responba);
                    if (mid_background_two != null) {
                        mid_background_two.setVisibility(RelativeLayout.VISIBLE);
                    }
                    try {
                        JSONObject jsonObject = new JSONObject(responba);
                        JSONArray rows = jsonObject.optJSONArray("rows");
                        // 自定义数据源
                        ArrayList<String> myList = new ArrayList<String>();

                        for (int i = 0; i < rows.length(); i++) {
                            JSONObject aitem = rows.optJSONObject(i);
                            String device_no = aitem.optString("device_no");
                            Log.d("aaaaa", "responba=device_no=" + device_no);

                            myList.add(device_no);
                        }

                        // 创建 ArrayAdapter
                        ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.spinner_devices_items, myList);

                        // 设置适配器
                        if (devices_spin_pot != null) {
                            devices_spin_pot.setAdapter(adapter);
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();

                    }
                }
                break;
                case DEVICES_ERROR: {

                }
                break;
                case DEVICES_CHECK: {
                    if (mWeiboDialog != null) {
                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                    }
                    String responbb = (String) msg.obj;
                    Log.d("aaaaa", "responbb=1=" + responbb);

                    try {
                        JSONObject jsonObject = new JSONObject(responbb);
                        int pers = jsonObject.optInt("pers");
                        if (pers == 1) {
                            Toast.makeText(mContext, mContext.getResources().getString(R.string.devices_error_one), Toast.LENGTH_SHORT).show();

                        } else {
                            initRegisterNumbers();
                            Toast.makeText(mContext, mContext.getResources().getString(R.string.devices_error_two), Toast.LENGTH_SHORT).show();
                            if (mani_background_one != null) {
                                mani_background_one.setVisibility(RelativeLayout.VISIBLE);
                            }

                            if (mani_background_two != null) {
                                mani_background_two.setVisibility(RelativeLayout.GONE);
                            }
                            initVersion();

                            mSelectIndexs = 0;
                            mDelayTime.sendEmptyMessageDelayed(1000, 300);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();

                    }
                }
                break;
                case DEVICES_CHECK_ERROR: {

                }
                break;
                case DEVICES_STATUS: {
                    if (mWeiboDialog != null) {
                        WeiboDialogUtils.closeDialog(mWeiboDialog);

                    }
                    String responbc = (String) msg.obj;
                    Log.d("aaaaa", "responbb=1=" + responbc);

                    try {
                        JSONObject jsonObject = new JSONObject(responbc);
                        int pers = jsonObject.optInt("pers");
                        initRegisterNumbers();
                        initVersion();

                        mSelectIndexs = 0;
                        mDelayTime.sendEmptyMessageDelayed(1000, 300);

                    } catch (JSONException e) {
                        e.printStackTrace();

                    }

                }
                break;
                case DEVICES_STATUS_ERROR: {

                }
                break;


            }
        }
    };

    private JSONArray mergeJsonArrays(JSONArray array1, JSONArray array2) throws JSONException {
        for (int i = 0; i < array2.length(); i++) {
            Object item = array2.get(i);

            array1.put(item);

        }

        return array1;
    }

    private Handler mDelayTime = new Handler() {
        public void handleMessage(android.os.Message msg) {
            mDelayTime.removeMessages(1000);
            mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));
            sendRequestInitDeviceStatus();

        }
    };
    private MyDatabaseInfor myDatabaseInfor = null;
    private SQLiteDatabase mBdread = null;
    private SQLiteDatabase mBdwrite = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myDatabaseInfor = new MyDatabaseInfor(getApplicationContext());
        mBdwrite = myDatabaseInfor.getWritableDatabase();
        mBdread = myDatabaseInfor.getReadableDatabase();

        mContext = this;
        mupdatemanager = new UpdateManger(this);
        File pathsFile = mContext.getDir("users", Context.MODE_PRIVATE);//Environment.getExternalStorageDirectory();//getDataDirectory();// mContext.getDir("users", Context.MODE_PRIVATE);
        mCurrenpahts = pathsFile.getAbsolutePath() + File.separator + "configjsons";

        getSupportActionBar().hide();
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window myWindow = this.getWindow();
        myWindow.setFlags(flag, flag);
        hideBottomUIMenu();


        initViews();


        if (juistVersion()) {
            if (mani_background_one != null) {
                mani_background_one.setVisibility(RelativeLayout.VISIBLE);
            }

            if (mani_background_two != null) {
                mani_background_two.setVisibility(RelativeLayout.GONE);
            }
            initVersion();
        } else {
            if (mani_background_one != null) {
                mani_background_one.setVisibility(RelativeLayout.GONE);
            }

            if (mani_background_two != null) {
                mani_background_two.setVisibility(RelativeLayout.VISIBLE);
            }
            initLogin();
        }

        //  jumpPage();

    }

    public void initViews() {
        mani_background_one = findViewById(R.id.mani_background_one);
        mani_background_two = findViewById(R.id.mani_background_two);
        mid_background_one = findViewById(R.id.mid_background_one);
        mid_background_two = findViewById(R.id.mid_background_two);
        devices_edittext = findViewById(R.id.devices_edittext);
        devices_button = findViewById(R.id.devices_button);
        devices_login_button = findViewById(R.id.devices_login_button);
        devices_spin_pot = findViewById(R.id.devices_spin_pot);


        devices_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

                sendRequestCheckAccount();
            }
        });

        devices_login_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));
                if (devices_spin_pot != null) {

                    String categoryName = devices_spin_pot.getSelectedItem().toString();
                    m_deviceNumbers = categoryName;
                    mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

                    sendRequestChangeStatus();
                }

            }
        });

        if (mani_background_one != null) {
            mani_background_one.setVisibility(RelativeLayout.GONE);
        }

        if (mani_background_two != null) {
            mani_background_two.setVisibility(RelativeLayout.GONE);
        }

        if (mid_background_one != null) {
            mid_background_one.setVisibility(RelativeLayout.GONE);
        }
        if (mid_background_two != null) {
            mid_background_two.setVisibility(RelativeLayout.GONE);
        }

        producewait_circlepg_bar_background = findViewById(R.id.producewait_circlepg_bar_background);
        main_local_infor_network_btn = findViewById(R.id.main_local_infor_network_btn);
        main_local_infor_network_btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mSelectIndexs = 0;
                mDelayTime.sendEmptyMessageDelayed(1000, 600);

            }
        });
        main_local_infor_local_btn = findViewById(R.id.main_local_infor_local_btn);
        main_local_infor_local_btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mSelectIndexs = 1;
                mDelayTime.sendEmptyMessageDelayed(1000, 600);


            }
        });
        //  producewait_circlepg_bar_background.setVisibility(RelativeLayout.VISIBLE);
        producewait_circlepg_bar = findViewById(R.id.producewait_circlepg_bar);
        producewait_circlepg_bar.setMax(100);
        mtxtVersionTip = (TextView) findViewById(R.id.txt_version_tips);
        mtxtErrorTip = (TextView) findViewById(R.id.txt_error_tips);


        //  mtxtErrorTip.setText(mContext.getResources().getString(R.string.main_local_device_two) +  mError);
        // updateApk("1.0.0.3");

    }


    public void updateApk(String updateVersion) {
        if (main_local_infor_network_btn != null) {
            main_local_infor_network_btn.setVisibility(RelativeLayout.GONE);
        }
        if (main_local_infor_local_btn != null) {
            main_local_infor_local_btn.setVisibility(RelativeLayout.GONE);
        }
        producewait_circlepg_bar_background.setVisibility(RelativeLayout.VISIBLE);
        mupdatemanager.producewait_circlepg_bar = producewait_circlepg_bar;
        String allPaths = Urlinfor.getmUrlinfor().getmUpdatePaths() + updateVersion + ".apk";
        Log.d("aaa", "devicematerial allPaths: " + allPaths);
        mupdatemanager.ApkDownloadUrl = allPaths;
        mupdatemanager.DownLoadApk();
    }


    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }

        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
            }
        });
    }


    public void jumpPage() {

        String speedcheacktb = "speedcheacktb";
        String speedcheacktbSql = "create table  IF NOT EXISTS speedcheacktb( pin integer primary key ,speed float DEFAULT 1 ,time float DEFAULT 0  )";

        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), speedcheacktb, speedcheacktbSql);


        String capacitytb = "capacitytb";
        String capacitytbSql = "create table  IF NOT EXISTS capacitytb( pin integer primary key ,surplus integer DEFAULT 0 ,capacity integer DEFAULT 0  )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), capacitytb, capacitytbSql);

        String pininfor = "pininfor";
        String pininforSql ="create table  IF NOT EXISTS pininfor( pin integer primary key ,reala integer DEFAULT 0  )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), pininfor, pininforSql);

        String salesouts = "salesouts";
        String salesoutsSql ="create table  IF NOT EXISTS salesouts( ordernums varchar(500) primary key ,salesvolumeOrderTime  varchar(300) ,secondMenuid  varchar(300)  , cupTypeid varchar(300) , contents text )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), salesouts, salesoutsSql);




        String cleartimea = "cleartimea";
        String cleartimeaSql ="create table  IF NOT EXISTS cleartimea( ordernums varchar(500) primary key , cleantimename varchar(300) , begin_time varchar(300), theoretical_time varchar(300)  )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), cleartimea, cleartimeaSql);


        String outmaterials = "outmaterials";
        String outmaterialsSql ="create table  IF NOT EXISTS outmaterials( ids INTEGER PRIMARY KEY AUTOINCREMENT, menuType integer   ,pin integer  ,weighs int  ,speed float DEFAULT 1 ,times int DEFAULT 0 ,nums integer  DEFAULT 0 )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), outmaterials, outmaterialsSql);



        String menumaterials = "menumaterials";
        String menumaterialsSql ="create table IF NOT EXISTS  menumaterials( ids INTEGER PRIMARY KEY AUTOINCREMENT,sendMeus integer  , menuType integer   ,nums integer  DEFAULT 0 )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), menumaterials, menumaterialsSql);


        //记录清晰状况
        String cleanRecord = "cleanRecord";
        String cleanRecordSql ="create table  IF NOT EXISTS cleanRecord( ids INTEGER PRIMARY KEY AUTOINCREMENT,cleanStartTime varchar(300)   ,cleanEndTime varchar(300) )";
        myDatabaseInfor.checkAndCreateTable(myDatabaseInfor.getWritableDatabase(), cleanRecord, cleanRecordSql);


        try {
            JSONObject objcta = new JSONObject(ContentInfor.getmUrlinfor().getInforMaterial());
            JSONArray devicematerial = objcta.optJSONArray("rows");
            for (int j = 0; j < devicematerial.length(); j++) {
                JSONObject itema = devicematerial.getJSONObject(j);
                String materialpins = itema.opt("materialpins").toString();
                String materialFull = itema.opt("materialFull").toString();
                Log.d("aaa", "devicematerial materialpins: " + materialpins);

                Cursor cursorb = null;
                cursorb = mBdread.rawQuery("select * from speedcheacktb where pin=? ", new String[]{(materialpins)});
                if ((cursorb != null && cursorb.getCount() > 0)) {

                } else {
                    ContentValues values = new ContentValues();

                    values.put("pin", Integer.parseInt(materialpins));


                    long insert = mBdwrite.insert("speedcheacktb", null, values);
                    Log.d("aaa", "devicematerial insert: " + insert);
                }

                cursorb = mBdread.rawQuery("select * from capacitytb where pin=? ", new String[]{(materialpins)});

                if (cursorb != null && cursorb.getCount() > 0) {

                    ContentValues values = new ContentValues();

                    values.put("capacity", Integer.parseInt(materialFull));


                    long insert = mBdwrite.update("capacitytb", values, "pin=? ", new String[]{(materialpins)});


                } else {

                    ContentValues values = new ContentValues();

                    Log.d("aaaaa", "handleMessage: materialpins==" + materialpins);
                    Log.d("aaaaa", "handleMessage: materialFull==" + materialFull);
                    values.put("pin", Integer.parseInt(materialpins));
                    values.put("capacity", Integer.parseInt(materialFull));


                    long insert = mBdwrite.insert("capacitytb", null, values);
                }

                cursorb = mBdread.rawQuery("select * from pininfor where pin=? ", new String[]{(materialpins)});

                if (cursorb != null && cursorb.getCount() > 0) {


                } else {

                    ContentValues values = new ContentValues();

                    Log.d("aaaaa", "handleMessage: materialpins==" + materialpins);
                    Log.d("aaaaa", "handleMessage: materialFull==" + materialFull);
                    values.put("pin", Integer.parseInt(materialpins));
                    values.put("reala", Integer.parseInt(materialpins));


                    long insert = mBdwrite.insert("pininfor", null, values);
                }


            }


            CleanDatabaseRecord.getmUrlinfor().clearCleanRunRecordMap();
            Cursor cursorb = null;


            cursorb = mBdread.rawQuery("select * from cleanRecord   ", null);

            Set<Integer> hashSetb = new HashSet<Integer>();

            if (cursorb != null && cursorb.getCount() > 0) {

                while (cursorb.moveToNext()) {
                    int ids = cursorb.getInt(cursorb.getColumnIndex("ids"));
                    String cleanStartTime = cursorb.getString(cursorb.getColumnIndex("cleanStartTime"));
                    String cleanEndTime = cursorb.getString(cursorb.getColumnIndex("cleanEndTime"));
                    // cleanStartTime ="2025-07-03";
                    //  cleanEndTime ="2025-07-03";
                    DebugUtils.printDebugInfo(String.valueOf(ids));
                    DebugUtils.printDebugInfo(cleanStartTime);
                    DebugUtils.printDebugInfo(cleanEndTime);
                    CleanDataRecord cleanDataRecord = new CleanDataRecord(String.valueOf(ids), cleanStartTime, cleanEndTime);
                    DebugUtils.printDebugInfo(cleanDataRecord.getCleantimeId());
                    DebugUtils.printDebugInfo(cleanDataRecord.getDetectStartNew());
                    DebugUtils.printDebugInfo(cleanDataRecord.getDetectEndNew());
                    hashSetb.add(ids);
                    CleanDatabaseRecord.getmUrlinfor().addCleanRunRecordMap(String.valueOf(ids), cleanDataRecord);
                }
            }


            JSONObject objctnewa = new JSONObject(ContentInfor.getmUrlinfor().getInforCleanTime());

            Log.d("aaa", "jumpPage==objctnewa=" + objctnewa.toString());
            JSONArray rowsnewa = objctnewa.optJSONArray("rows");
            Set<Integer> hashSeta = new HashSet<Integer>();

            for (int j = 0; j < rowsnewa.length(); j++) {
                JSONObject itema = rowsnewa.getJSONObject(j);
                if (itema.has("cleantime_id") && itema.has("detect_new") && itema.has("detect_interval_new") && itema.has("detect_start_new") && itema.has("detect_end_new") && itema.has("enforce")) {
                    String cleantime_id = "";

                    if (!itema.isNull("cleantime_id")) {
                        cleantime_id = itema.optString("cleantime_id");
                    }
                    String detect_new = "";
                    if (!itema.isNull("detect_new")) {
                        detect_new = itema.optString("detect_new");
                    }

                    String detect_interval_new = "";
                    if (!itema.isNull("detect_interval_new")) {
                        detect_interval_new = itema.optString("detect_interval_new");
                    }

                    String detect_start_new = "";
                    if (!itema.isNull("detect_start_new")) {
                        detect_start_new = itema.optString("detect_start_new");
                    }


                    String detect_end_new = "";
                    if (!itema.isNull("detect_end_new")) {
                        detect_end_new = itema.optString("detect_end_new");
                    }

                    String enforce = "";
                    if (!itema.isNull("enforce")) {
                        enforce = itema.optString("enforce");
                    }
                    String cleantime_name = "";
                    if (!itema.isNull("cleantime_name")) {
                        cleantime_name = itema.optString("cleantime_name");
                    }

                    JSONArray children = itema.optJSONArray("children");

                    hashSeta.add(Integer.parseInt(cleantime_id));
                    CleanRunRecord cleanRunRecord = new CleanRunRecord(cleantime_id, detect_new, detect_interval_new, detect_start_new, detect_end_new, enforce, cleantime_name, children.toString());

                    CleanConfigRecord.getmUrlinfor().addCleanRunRecordMap(cleantime_id, cleanRunRecord);

                    if (!hashSetb.contains(Integer.parseInt(cleantime_id))) {
                        ContentValues values = new ContentValues();
                        values.put("ids", Integer.parseInt(cleantime_id));
                        values.put("cleanStartTime", "");
                        values.put("cleanEndTime", "");
                        long insert = mBdwrite.insert("cleanRecord", null, values);
                        CleanDatabaseRecord.getmUrlinfor().addCleanRunRecordMap(cleantime_id, new CleanDataRecord(cleantime_id, "", ""));

                    }
                }

            }


            for (Integer num : hashSetb) {
                Log.d("SetTraversal", "Number: " + num);
                // 或者做其他操作
                if (!hashSeta.contains(num)) {
                    long staus = mBdwrite.delete("cleanRecord", "ids = ? ", new String[]{num + ""});
                    CleanDatabaseRecord.getmUrlinfor().removeCleanRunRecordMapIndex(String.valueOf(num));
                }
            }

            Log.d("aaa", "jumpPage:== CleanDatabaseRecord.getmUrlinfor()==" + CleanDatabaseRecord.getmUrlinfor().toString());
            Log.d("aaa", "jumpPage:== CleanConfigRecord.getmUrlinfor()==" + CleanConfigRecord.getmUrlinfor().toString());


        } catch (JSONException e) {
            e.printStackTrace();

        }


        Intent intent = new Intent(MainActivity.this, HomePages.class);    //切换Login Activity至User Activity

        startActivity(intent);

        finish();
    }


    //判断版本
    private boolean juistVersion() {
        Cursor cursor = null;

        String devicenumNumbers = "";

        cursor = mBdread.rawQuery("select * from devicerigister where verNumber=?", new String[]{0 + ""});

        if (cursor != null && cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                devicenumNumbers = cursor.getString(cursor.getColumnIndex("versions"));

            }
        }
        if (!mIsVirtual) {
            if (devicenumNumbers.length() > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    //初始化版本
    public void initVersion() {
        Cursor cursor = null;


        cursor = mBdread.rawQuery("select * from devicerigister where verNumber=?", new String[]{0 + ""});

        if (cursor != null && cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                mdevicenums = cursor.getString(cursor.getColumnIndex("versions"));
                misversion = true;
            }
        }
        if (mIsVirtual) {
            misversion = true;
            mdevicenums = "202509252";// 1752196515 "16837684651";// 16837684651 "1726221544"; //"1726221544";// "1721351125";//"1721268401";//123456789"1717399534";// "1683768465"; //"1683768465"; //"1701827931";
            //  mdevicenums = "1667803087";
        }


        if (!misversion) {
            long timeStamp = System.currentTimeMillis() / 1000;
            mdevicenums = String.valueOf(timeStamp);
            ContentValues values = new ContentValues();
            values.put("verNumber", 0);
            values.put("versions", mdevicenums);


            long insert = mBdwrite.insert("devicerigister", null, values);

        }

        Log.d("aaa", "initVersion: mdevicenums=" + mdevicenums);

        Urlinfor.getmUrlinfor().setMdevicenums(mdevicenums);
        if (mtxtVersionTip != null) {
            mtxtVersionTip.setText(mContext.getResources().getString(R.string.main_local_device_one) + Urlinfor.getmUrlinfor().getMdevicenums());

        }
    }

    public void initRegisterNumbers() {
        mdevicenums = m_deviceNumbers;
        ContentValues values = new ContentValues();
        values.put("verNumber", 0);
        values.put("versions", mdevicenums);


        long insert = mBdwrite.insert("devicerigister", null, values);

    }

    //初始化登录界面
    private void initLogin() {
        if (mLoginViews == null) {
            mLoginViews = new LoginViews(mContext);
        }
        mLoginViews.show();
        mLoginViews.setBtnOnClick(new View.OnClickListener() {
            public void onClick(View v) {
                String username = "";
                String userPwd = "";
                if (mLoginViews != null) {
                    username = mLoginViews.getUserName();
                }
                if (mLoginViews != null) {
                    userPwd = mLoginViews.getUserPwd();
                }
                //mLoginViews.dismiss();
                m_userNames = username;

                m_userPwds = getMD5(userPwd);
                Log.d("aaa", "onClick:===username=" + username);
                Log.d("aaa", "onClick:===userPwd=" + userPwd);
                Log.d("aaa", "onClick:===m_userPwds=" + m_userPwds);
                mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));
                sendRequestInitDeviceLogins();
            }

        });
    }

    private void sendRequestChangeStatus() {


        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getChangeStatus();
                Log.d("aaaaa", "sendRequestChangeStatus_strUrl==" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                    /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }
                    */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);

                    Log.d("aaaaa", "sendRequestChangeStatus_device_no:==" + m_deviceNumbers);

                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + m_deviceNumbers);

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "sendRequestChangeStatus=abc=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;//result.replace("null","\"0\"");;
                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = DEVICES_STATUS;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = DEVICES_STATUS_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }

    private void sendRequestCheckAccount() {


        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getCheckAccount();
                Log.d("aaaaa", "sendRequestBrandDeviceListstrUrl==" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }
                    */

                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    m_deviceNumbers = devices_edittext.getText().toString();
                    Log.d("aaaaa", "device_no:==" + DataInfors.getmUrlinfor().getBrandId());

                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + m_deviceNumbers);

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "sendRequestInitDeviceLogins=abc=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = DEVICES_CHECK;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = DEVICES_CHECK_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }


    private void sendRequestBrandDeviceList() {


        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getBrandDeviceList();
                Log.d("aaaaa", "sendRequestBrandDeviceListstrUrl==" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }
                    */

                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    Log.d("aaaaa", "sendRequestBrandDeviceListbrand_id:==" + DataInfors.getmUrlinfor().getBrandId());

                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("brand_id=" + DataInfors.getmUrlinfor().getBrandId());

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "sendRequestBrandDeviceList=abc=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = DEVICES_LIST;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = DEVICES_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }

    private void sendRequestInitDeviceLogins() {


        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getDeviceloginChecks();
                Log.d("aaaaa", "strUrlstrUrl=11=" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                        */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    Log.d("aaaaa", "device_no:==" + Urlinfor.getmUrlinfor().getMdevicenums());
                    Log.d("aaaaa", "userName:==" + m_userNames);
                    Log.d("aaaaa", "userPwd:==" + m_userPwds);
                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + Urlinfor.getmUrlinfor().getMdevicenums());
                    dop.writeBytes("&userName=" + m_userNames);
                    dop.writeBytes("&userPwd=" + m_userPwds);
                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "sendRequestInitDeviceLogins=abc=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = SCREEN_LOGIN;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = SCREEN_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }

    public String getMD5(String input) {
        try {
            // Create MD5 Hash
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(input.getBytes());
            byte messageDigest[] = digest.digest();

            // Create Hex String
            StringBuilder hexString = new StringBuilder();
            for (byte aMessageDigest : messageDigest) {
                String h = Integer.toHexString(0xFF & aMessageDigest);
                while (h.length() < 2) h = "0" + h;
                hexString.append(h);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

    private void sendRequestInitDeviceStatus() {

        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getRegisteredEquipment();
                Log.d("aaaaa", "strUrlstrUrl==" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                        */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + Urlinfor.getmUrlinfor().getMdevicenums());
                    dop.writeBytes("&local_version=" + Urlinfor.getmUrlinfor().getmVersion());
                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "minqq=abc=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = SCREEN_STATUS;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = SCREEN_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }

    private void sendRequestInitDeviceMaterial() {

        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getDeviceMaterial();
                Log.d("aaaaa", "strUrlstrUrl=1=" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                        */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + Urlinfor.getmUrlinfor().getMdevicenums());

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "minqq=abc1=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = SCREEN_MATERIAL;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = SCREEN_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }


    private void sendRequestInitDeviceCleantime() {

        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getCleantime();
                Log.d("aaaaa", "strUrlstrUrl==" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                        */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + Urlinfor.getmUrlinfor().getMdevicenums());

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "minqq=abc2=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = SCREEN_CLEAN;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = SCREEN_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }


    private void sendRequestInitDeviceMkesales() {

        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getMkesales();
                Log.d("aaaaa", "strUrlstrUrl=aa=" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                        */
                    urlConn.connect();

                    Log.d("aaaaa", "shopCode:==" + Urlinfor.getmUrlinfor().getShopInformationNo());
                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    // dop.writeBytes("device_no=" + Urlinfor.getmUrlinfor().getMdevicenums());
                    dop.writeBytes("shopCode=" + Urlinfor.getmUrlinfor().getShopInformationNo());

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "minqq=abc=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = SCREEN_MAKE;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = SCREEN_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }


    private void sendRequestInitDeviceMenus() {

        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(MainActivity.this, mContext.getResources().getString(R.string.loading_text));

        new Thread(new Runnable() {

            @Override
            public void run() {
                String strUrl = Urlinfor.getmUrlinfor().getMenus();
                Log.d("aaaaa", "strUrlstrUrl=1=" + strUrl);
                URL url = null;
                try {
                    long currentTime = System.currentTimeMillis();
                    String timeNow = new SimpleDateFormat("yyyy-MM-dd").format(currentTime);
                    url = new URL(strUrl);
                    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setDoOutput(true);
                    urlConn.setRequestMethod("POST");
                    urlConn.setUseCaches(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Charset", "utf-8");
                       /*
                    if (urlConn instanceof HttpsURLConnection) {
                        try {
                            SSLContext sslContext = HttpsUtil.getSSLContextWithCer();

                            if (sslContext != null) {
                                SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
                                ((HttpsURLConnection) urlConn).setDefaultSSLSocketFactory(sslSocketFactory);

                            }
                        } catch (Exception e) {
                            e.printStackTrace();

                        }

                    }

                        */
                    urlConn.connect();

                    Log.d("aaaaa", "timeNow:==" + timeNow);
                    DataOutputStream dop = new DataOutputStream(urlConn.getOutputStream());
                    dop.writeBytes("device_no=" + Urlinfor.getmUrlinfor().getMdevicenums());
                    dop.writeBytes("&page=" + mPageIndexs);
                    dop.writeBytes("&limit=" + mPageLimit);

                    dop.flush();
                    dop.close();
                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String result = "";
                    String readline = null;
                    while ((readline = bufferReader.readLine()) != null) {
                        result += readline;
                    }
                    bufferReader.close();
                    urlConn.disconnect();
                    //  String a = result.substring(0,result.length()/ 3);
                    //  String b= result.substring(result.length()/ 3,result.length()*2/ 3);
                    //  String c= result.substring(result.length()*2/ 3,result.length());
                    Log.d("aaaaa", "miss=a=" + result);
                    //   Log.d("aaaaa", "minqq=aa=" + a);

                    // Log.d("aaaaa", "minqq=aaa=" + b);
                    // Log.d("aaaaa", "minqq=aaaaaa=" + c);

                    if (result.length() > 0) {
                        String resulta = result;

                        Message msg = new Message();
                        String str1;
                        str1 = resulta;
                        msg.what = SCREEN_MENU;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    } else {

                        Message msg = new Message();
                        String str1;
                        str1 = "";
                        msg.what = SCREEN_ERROR;
                        msg.obj = str1;
                        handler.sendMessage(msg);
                    }


                } catch (IOException e) {

                    Log.d("aaaaa", "222=");

                    e.printStackTrace();
                }

            }
        }).start();//这个start()方法不要忘记了

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        mBdwrite.close();
        mBdread.close();


    }

    public void saveMaterialText(String conta) {

        String infors = conta;

        // Toast.makeText(mContext, infors, Toast.LENGTH_SHORT).show();
        FileOutputStream output = null;
        // File pathsFile = mContext.getDir("users", Context.MODE_PRIVATE);//Environment.getExternalStorageDirectory();//getDataDirectory();// mContext.getDir("users", Context.MODE_PRIVATE);
        String paths = mCurrenpahts;// pathsFile.getAbsolutePath()+ File.separator + "configjsons";
        Log.i("ddd-infors", infors);
        //   paths = paths.replace(mCurrenpages+"/","");

        File appDir = new File(paths);
        Log.i("ddd", paths);
        if (!appDir.exists()) {
            boolean bs = appDir.mkdir();
            if (bs) {
                Log.i("ddd-1", "true");
            } else {
                Log.i("ddd-1", "false");
            }

        }
        paths = paths + File.separator + "configMaterial.json";
        Log.i("ddd-1", paths);
        // Toast.makeText(mContext, paths, Toast.LENGTH_SHORT).show();
        File f = null;
        try {
            f = new File(paths);
            if (f.exists()) {
                Log.i("ccc", "有这个文件");

            } else {
                Log.i("ccc", "没有这个文件");
                f.createNewFile();
            }
        } catch (Exception e) {
            Log.i("ccc", "崩溃");
            return;
        }
        try {

            FileOutputStream fout = new FileOutputStream(f);


            fout.write(infors.getBytes());
            fout.flush();
            fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public void readMaterialText() {
        FileInputStream input = null;
        // File pathsFile =mContext.getDir("users", Context.MODE_PRIVATE);// Environment.getExternalStorageDirectory(); //getDataDirectory();//mContext.getDir("users", Context.MODE_PRIVATE);
        String paths = mCurrenpahts;
        //  paths = paths.replace(mCurrenpages+"/","");

        File appDir = new File(paths);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        paths = paths + File.separator + "configMaterial.json";
        Log.i("bbb-paths", paths);
        File f = null;
        try {
            f = new File(paths);
            if (f.exists()) {
                Log.i("bbb", "有这个文件");

            } else {
                Log.i("bbb", "没有这个文件");
                return;
            }
        } catch (Exception e) {
            Log.i("bbb", "崩溃");
            return;
        }


        String infor = "";
        StringBuilder sb = new StringBuilder();
        try {

            InputStream in = null;
            in = new FileInputStream(f);
            byte[] er = new byte[in.available()];
            int tempbyte;
            while (in.read(er) != -1) {
                String infora = new String(er);
                infor += infora;
            }
//            while ((tempbyte = in.read()) != -1) {
//                sb.append((char) tempbyte);
//            }
            in.close();
            // infor += sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.i("bbb-infor", infor);

        if (infor.length() > 0) {
            ContentInfor.getmUrlinfor().setInforMaterial(infor);
        }

    }


    public void saveCleanTimeText(String conta) {

        String infors = conta;

        // Toast.makeText(mContext, infors, Toast.LENGTH_SHORT).show();
        FileOutputStream output = null;
        // File pathsFile = mContext.getDir("users", Context.MODE_PRIVATE);//Environment.getExternalStorageDirectory();//getDataDirectory();// mContext.getDir("users", Context.MODE_PRIVATE);
        String paths = mCurrenpahts;// pathsFile.getAbsolutePath()+ File.separator + "configjsons";
        Log.i("ddd-infors", infors);
        //   paths = paths.replace(mCurrenpages+"/","");

        File appDir = new File(paths);
        Log.i("ddd", paths);
        if (!appDir.exists()) {
            boolean bs = appDir.mkdir();
            if (bs) {
                Log.i("ddd-1", "true");
            } else {
                Log.i("ddd-1", "false");
            }

        }
        paths = paths + File.separator + "configCleanTime.json";
        Log.i("ddd-1", paths);
        // Toast.makeText(mContext, paths, Toast.LENGTH_SHORT).show();
        File f = null;
        try {
            f = new File(paths);
            if (f.exists()) {
                Log.i("ccc", "有这个文件");

            } else {
                Log.i("ccc", "没有这个文件");
                f.createNewFile();
            }
        } catch (Exception e) {
            Log.i("ccc", "崩溃");
            return;
        }
        try {

            FileOutputStream fout = new FileOutputStream(f);


            fout.write(infors.getBytes());
            fout.flush();
            fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public void readCleanTimText() {
        FileInputStream input = null;
        // File pathsFile =mContext.getDir("users", Context.MODE_PRIVATE);// Environment.getExternalStorageDirectory(); //getDataDirectory();//mContext.getDir("users", Context.MODE_PRIVATE);
        String paths = mCurrenpahts;
        //  paths = paths.replace(mCurrenpages+"/","");

        File appDir = new File(paths);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        paths = paths + File.separator + "configCleanTime.json";
        Log.i("bbb-paths", paths);
        File f = null;
        try {
            f = new File(paths);
            if (f.exists()) {
                Log.i("bbb", "有这个文件");

            } else {
                Log.i("bbb", "没有这个文件");
                return;
            }
        } catch (Exception e) {
            Log.i("bbb", "崩溃");
            return;
        }


        String infor = "";
        StringBuilder sb = new StringBuilder();
        try {

            InputStream in = null;
            in = new FileInputStream(f);
            byte[] er = new byte[in.available()];
            int tempbyte;
            while (in.read(er) != -1) {
                String infora = new String(er);
                infor += infora;
            }
//            while ((tempbyte = in.read()) != -1) {
//                sb.append((char) tempbyte);
//            }
            in.close();
            // infor += sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.i("bbb-infor", infor);

        if (infor.length() > 0) {
            ContentInfor.getmUrlinfor().setInforCleanTime(infor);

        }

    }

    public void saveMenusText(String conta) {

        String infors = conta;

        // Toast.makeText(mContext, infors, Toast.LENGTH_SHORT).show();
        FileOutputStream output = null;
        // File pathsFile = mContext.getDir("users", Context.MODE_PRIVATE);//Environment.getExternalStorageDirectory();//getDataDirectory();// mContext.getDir("users", Context.MODE_PRIVATE);
        String paths = mCurrenpahts;// pathsFile.getAbsolutePath()+ File.separator + "configjsons";
        Log.i("ddd-infors", infors);
        //   paths = paths.replace(mCurrenpages+"/","");

        File appDir = new File(paths);
        Log.i("ddd", paths);
        if (!appDir.exists()) {
            boolean bs = appDir.mkdir();
            if (bs) {
                Log.i("ddd-1", "true");
            } else {
                Log.i("ddd-1", "false");
            }

        }
        paths = paths + File.separator + "configMenus.json";
        Log.i("ddd-1", paths);
        // Toast.makeText(mContext, paths, Toast.LENGTH_SHORT).show();
        File f = null;
        try {
            f = new File(paths);
            if (f.exists()) {
                Log.i("ccc", "有这个文件");

            } else {
                Log.i("ccc", "没有这个文件");
                f.createNewFile();
            }
        } catch (Exception e) {
            Log.i("ccc", "崩溃");
            return;
        }
        try {

            FileOutputStream fout = new FileOutputStream(f);


            fout.write(infors.getBytes());
            fout.flush();
            fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public void readMenusText() {
        FileInputStream input = null;
        // File pathsFile =mContext.getDir("users", Context.MODE_PRIVATE);// Environment.getExternalStorageDirectory(); //getDataDirectory();//mContext.getDir("users", Context.MODE_PRIVATE);
        String paths = mCurrenpahts;
        //  paths = paths.replace(mCurrenpages+"/","");

        File appDir = new File(paths);
        if (!appDir.exists()) {
            appDir.mkdir();
        }
        paths = paths + File.separator + "configMenus.json";
        Log.i("bbb-paths", paths);
        File f = null;
        try {
            f = new File(paths);
            if (f.exists()) {
                Log.i("bbb", "有这个文件");

            } else {
                Log.i("bbb", "没有这个文件");
                return;
            }
        } catch (Exception e) {
            Log.i("bbb", "崩溃");
            return;
        }


        String infor = "";
        StringBuilder sb = new StringBuilder();
        try {

            InputStream in = null;
            in = new FileInputStream(f);
            byte[] er = new byte[in.available()];
            int tempbyte;
            while (in.read(er) != -1) {
                String infora = new String(er);
                infor += infora;
            }
//            while ((tempbyte = in.read()) != -1) {
//                sb.append((char) tempbyte);
//            }
            in.close();
            // infor += sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.i("bbb-infor", infor);

        if (infor.length() > 0) {
            ContentInfor.getmUrlinfor().setInforMenus(infor);

        }

    }
}
